<template>
  <div class="container">
    <el-row :gutter="3" class="cust-r-title">
      <el-col :span="3">
        <p class="cust-r-l">客户关系管理</p>
      </el-col>
      <el-col :span="6" :offset="15">
        <el-button class="cust-r-c" @click="digShow"
          >+&nbsp;&nbsp;增加映射关系</el-button
        >
          <el-button class="cust-r-r" @click="syncCustPro">自动同步集团客户到省</el-button>
      </el-col>
    </el-row>
    <pro-select-city
      :tableCol="tableCol"
      :queryData="queryData"
      @getCustList="getCustList"
    ></pro-select-city>
    <el-table
      ref="custArr"
      :data="custArr"
      border
      stripe
      :header-cell-style="{
        background: '#F2F2F2',
        color: '#333',
      }"
      tooltip-effect="dark"
      max-height="500"
      style="width: 100%"
    >
      <el-table-column label="序号" type="index" align="center">
      </el-table-column>
      <el-table-column
        prop="provinceName"
        label="省份"
        show-overflow-tooltip
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="lanName"
        label="地市"
        show-overflow-tooltip
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="oldPartyCode"
        label="集团客户编码"
        show-overflow-tooltip
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="provinceCustId"
        label="省客户ID"
        show-overflow-tooltip
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="provinceCustNumber"
        label="省客户编码"
        show-overflow-tooltip
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="createDate"
        label="创建时间"
        show-overflow-tooltip
        align="center"
      >
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button
            class="editBtn"
            @click="handleClick(scope.row)"
            type="text"
            size="small"
            >修改</el-button
          >
          <el-button
            class="delBtn"
            type="text"
            size="small"
            @click="delectClick(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      @current-change="pageHandleCurrentChange"
      @size-change="pageHandleSizeChange"
      :current-page="parseInt(tablePage.pageIndex)"
      :page-size="parseInt(tablePage.pageSize)"
      layout="total, sizes, prev, pager, next, jumper"
      :page-sizes="[10, 20, 30, 50, 100]"
      :total="parseInt(tablePage.rowCount)"
      class="m-pagination"
    >
    </el-pagination>
    <div class="btnBox">
      <el-button type="primary" class="returnBtn" @click="returnClick">
        返回
      </el-button>
    </div>
    <el-dialog
      ref="addcustmer"
      title="新建关系"
      width="75%"
      :visible.sync="outerVisible"
      :close-on-click-modal="false"
      :withHeader="false"
      class="m-dialog"
      @close="closeShow"
    >
      <el-dialog
        width="75%"
        title="查询省客户"
        :visible.sync="innerVisible"
        :close-on-click-modal="false"
        append-to-body
      >
        <el-form label-width="80px">
          <el-row :gutter="3" class="m-contain">
            <el-col :span="7" :offset="1">
              <el-form-item label="客户名称" class="u-ipt">
                <el-input
                  placeholder="请输入客户名称"
                  v-model="getProData.custName"
                  class="input-with-select"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="7">
              <el-form-item label="身份证号" class="u-ipt">
                <el-input
                  placeholder="请输入身份证号"
                  v-model="getProData.idCard"
                  class="input-with-select"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="7">
              <el-form-item label="省客户ID" class="u-ipt">
                <el-input
                  placeholder="请输入省客户ID"
                  v-model="getProData.proId"
                  class="input-with-select"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="7" :offset="1">
              <el-form-item label="证件类型" class="u-ipt">
                <el-select
                  @change="ChangeIdCard"
                  v-model="getProData.idType"
                  placeholder="请选择"
                  class="m-select"
                >
                  <el-option
                    v-for="item in idCardList"
                    :key="item.code"
                    :label="item.name"
                    :value="item.code"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="7">
              <el-form-item label="证件号码" class="u-ipt">
                <el-input
                  placeholder="请输入证件号码"
                  v-model="getProData.idCardNum"
                  class="input-with-select"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-button class="checkBtn" @click="checkProCust"> 查询 </el-button>
            </el-col>
          </el-row>
        </el-form>
        <el-table
          ref="proList"
          :data="proList.slice(
            (proTablePage.pageIndex - 1) * proTablePage.pageSize,
            proTablePage.pageIndex * proTablePage.pageSize
          )"
          border
          stripe
          :header-cell-style="{
            background: '#F2F2F2',
            color: '#333',
          }"
          tooltip-effect="dark"
          style="width: 100%"
          @row-click="chooseProCust"
        >
          <el-table-column
            prop="commonRegionName"
            label="地市"
            show-overflow-tooltip
            align="center"
          >
          </el-table-column>
          <!-- <el-table-column
            prop="lanId"
            label="地市"
            show-overflow-tooltip
            align="center"
          >
          </el-table-column> -->
          <el-table-column
            prop="custName"
            label="客户名称"
            show-overflow-tooltip
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="custId"
            label="省客户ID"
            show-overflow-tooltip
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="custNumber"
            label="省客户编码"
            show-overflow-tooltip
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="createDate"
            label="创建时间"
            show-overflow-tooltip
            align="center"
          >
          </el-table-column>
        </el-table>
        <el-pagination
          background
          @current-change="proPageChange"
          :current-page="parseInt(proTablePage.pageIndex)"
          :page-size="parseInt(proTablePage.pageSize)"
          layout="total, prev, pager, next, jumper"
          :total="parseInt(proTablePage.rowCount)"
          class="m-pagination"
        >
        </el-pagination>
      </el-dialog>
      <pro-select-city
        ref="ProSelectCity"
        btnText="查询省客户"
        :tableCol="tableCol"
        :queryData="queryData1"
        @innerDigShow="innerDigShow"
      ></pro-select-city>
      <div class="btnBox">
        <el-button type="primary" class="confirmBtn" @click="addCust"
          >确定</el-button
        >
        <el-button type="info" class="returnBtn" @click="closeShow"
          >取消</el-button
        >
      </div>
    </el-dialog>
    <el-dialog
      width="80%"
      title="修改关系"
      :visible.sync="changeVisible"
      :close-on-click-modal="false"
      append-to-body
    >
      <el-dialog
        width="75%"
        title="查询集团客户"
        :close-on-click-modal="false"
        :visible.sync="changeInnerVisible"
        append-to-body
      >
        <el-form label-width="70px">
          <el-row :gutter="3" class="m-contain">
            <el-col :span="7" :offset="1">
              <el-form-item label="客户名称" class="u-ipt">
                <el-input
                  placeholder="请输入客户名称"
                  v-model="getJtData.custName"
                  class="input-with-select"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="7">
              <el-form-item label="客户编码" class="u-ipt">
                <el-input
                  placeholder="请输入"
                  v-model="getJtData.oldPartyCode"
                  class="input-with-select"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="7">
              <el-form-item label="身份证号码" class="u-ipt">
                <el-input
                  placeholder="请输入身份证号"
                  v-model="getJtData.idCardNum"
                  class="input-with-select"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="7" :offset="1">
              <el-form-item label="证件类型" class="u-ipt">
                <el-select
                  @change="ChangeIdCard"
                  v-model="getJtData.idType"
                  placeholder="请选择"
                >
                  <el-option
                    v-for="item in idCardList"
                    :key="item.code"
                    :label="item.name"
                    :value="item.code"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="7">
              <el-form-item label="证件号码" class="u-ipt">
               <el-input
                  placeholder="请输入"
                  v-model="getJtData.certNum"
                  class="input-with-select"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-button class="checkBtn" @click="checkBtn" style="margin-left:20px"> 查询 </el-button>
            </el-col>
          </el-row>
        </el-form>
        <el-table
          ref="proCustArr"
          :data="jtList"
          border
          stripe
          :header-cell-style="{
            background: '#F2F2F2',
            color: '#333',
          }"
          tooltip-effect="dark"
          style="width: 100%"
          @row-click="chooseJtCust"
        >
          <el-table-column
            prop="regionName"
            label="营销责任地"
            show-overflow-tooltip
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="custName"
            label="客户名称"
            show-overflow-tooltip
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="custManager"
            label="客户经理"
            show-overflow-tooltip
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="oldPartyCode"
            label="客户编码"
            show-overflow-tooltip
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="createDate"
            label="创建时间"
            show-overflow-tooltip
            align="center"
          >
          </el-table-column>
        </el-table>
        <el-pagination
          background
          @current-change="jtPageChange"
          :current-page="parseInt(jtTablePage.pageIndex)"
          :page-size="parseInt(jtTablePage.pageSize)"
          layout="total, prev, pager, next, jumper"
          :total="parseInt(jtTablePage.rowCount)"
          class="m-pagination"
        >
        </el-pagination>
      </el-dialog>
      <el-form 
        ref="changeRowInfo"
        :model="changeRowInfo"
      >
        <el-row :gutter="3" class="m-contain">
          <el-col :span="5">
            <el-form-item label="省份" class="u-ipt jt-ipt" required label-width="50px">
              <el-select
                v-model="changeRowInfo.provinceName"
                class="m-select"
                disabled
              >
                <el-option value=""> </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="地市" class="u-ipt jt-ipt" required label-width="50px">
              <el-select
                v-model="changeRowInfo.lanName"
                placeholder="请选择"
                class="m-select"
                disabled
              >
                <el-option value=""> </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="省客户ID" class="u-ipt jt-ipt" required label-width="70px">
              <el-input
                v-model="changeRowInfo.provinceCustId"
                class="input-with-select jtInput"
                disabled
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="集团客户编码" class="u-ipt jt-ipt" required label-width="100px">
              <el-input
                v-model="changeRowInfo.jtCustNumber"
                class="input-with-select"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <el-button class="checkBtn" @click="checkCustBtn()">
              查询集团客户
            </el-button>
          </el-col>
        </el-row>
      </el-form>
      <div class="btnBox">
        <el-button type="primary" class="confirmBtn" @click="jtCustBtn"
          >确定</el-button
        >
        <el-button type="info" class="returnBtn" @click="closeShow"
          >取消</el-button
        >
      </div>
    </el-dialog>
    <el-dialog
      width="60%"
      title="自动同步客户"
      :close-on-click-modal="false"
      :visible.sync="syncVisible"
      append-to-body
    >
      <pro-select-city
        ref="ProSelectCity"
        :tableCol="proCityForm"
        @getCustList="getCustList"
        :queryData="queryData2"
      ></pro-select-city>
      <div class="btnBox">
        <el-button type="primary" class="confirmBtn" @click="syncCustBtn"
          >确定</el-button
        >
        <el-button type="info" class="returnBtn" @click="closeShow"
          >取消</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import CustRelationManage from "@/api/customer/CustRelationManage";
import ProSelectCity from "@/views/customer/components/proSelectCity";
export default {
  data() {
    return {
      custArr: [], //查询的数据
      tableCol: {
        col: [6, 6, 6, 0],
        offset: 2,
        label: "",
        custIsShow: true,
        amountIsShow: false,
        checkShow:true
      },
      queryData: {
        proSelect: "", //选择的省
        citySelect: "", //选择的城市
        proId: "", //省客户id
        proAId:"",//省账户id
      },//查询列表
      queryData1: {
        proSelect: "", //选择的省
        citySelect: "", //选择的城市
        proId: "", //省客户id
        proAId:"",//省账户id
        provinceCustNumber:''
      },//添加映射关系
      queryData2: {
        proSelect: "", //选择的省
        citySelect: "", //选择的城市
        proId: "", //省客户id
        proAId:"",//省账户id
      },//修改集团关系
      proCityForm: {
        col: [10, 11, 0, 0],
        offset: 3,
        label: "",
        custIsShow: true,
        amountIsShow: false,
        checkShow:false
      },
      proCustArr: [], //省客户查询的数据
      tablePage: {
        pageIndex: 1, //当前页码
        pageSize: 10, //每页多少条
        rowCount: 0, //总条数
      }, //查询列表分页
      proTablePage: {
        pageIndex: 1, //当前页码
        pageSize: 5, //每页多少条
        rowCount: 0, //总条数
      }, //省客户查询列表
      jtTablePage: {
        pageIndex: 1, //当前页码
        pageSize: 5, //每页多少条
        rowCount: 0, //总条数
      }, //集团查询列表分页
      getProData: {
        custName: "",
        idCard: "",
        proId: "",
        idType: "",
        idCardNum:"",
      }, //查询省客户
      getJtData: {
        custName: "",
        oldPartyCode:"",
        idCardNum: "",//身份证号码
        idType: "",
        certNum: "",
      }, //查询集团客户
      proList: [
        
      ], //查询到省客户列表的数据
      jtList: [
      ], //查询到的集团客户列表数据
      outerVisible: false,
      innerVisible: false,
      changeVisible: false, //修改关系弹窗显示按钮
      changeInnerVisible: false, //修改关系内弹窗
      syncVisible:false,//自动同步客户弹窗
      proSelectVal: "", //子组件传过来的省id，用于查询省客户列表
      idCardList: [], //证件类型列表
      changeRowInfo: {}, //修改当前行的信息
      jtCustNumberOld: "", //老的集团客户编码
      custName:'',//客户名称
    };
  },

  components: {
    ProSelectCity,
  },

  // computed: {},

  mounted() {
    // 初始化客户列表
    this.getCusRelList();
    this.initValueIdType();
    this.getCustCommon()
  },

  methods: {
    async getCusRelList() {
      let params = {
        pageIndex: this.tablePage.pageIndex,
        pageSize: this.tablePage.pageSize,
        custNumber: this.$route.query.oldPartyCode,
        provinceId: this.proSelectVal.proSelect,
        lanId: "",
        provinceCustId: "",
      };
      const response = await CustRelationManage.getCusRelList(params);
      if (response.code == 200) {
        this.custArr = response.meta.executeSqlResp;
        this.tablePage.rowCount = response.meta.pageInfo.rowCount;
        this.custArr.forEach((item) => {
          item.createDate =
            item.createDate.substring(0, 4) +
            "-" +
            item.createDate.substring(4, 6) +
            "-" +
            item.createDate.substring(6, 8) +
            " " +
            item.createDate.substring(8, 10) +
            ":" +
            item.createDate.substring(10, 12) +
            ":" +
            item.createDate.substring(12, 14);
        });
      }
    },
    async initValueIdType() {
      const response = await CustRelationManage.initValue({
        flag: "cert_type",
      });
      if (response.code == 200) {
        this.idCardList = response.meta.customers;
        this.idCardList.unshift({name:"请选择",code:""})
      }
    },
    //获取客户名称
    async getCustCommon(){
      let params = {
        params: "custId:" + this.$route.query.custId,
        sqlId: "2021071601",
      };
      const response = await CustRelationManage.getCustCommon(params);
      if(response.code == 200){
        this.custName = this.isNull(response.meta.custName);
      }
    },
    //同步集团客户到省客户
    async syncCustBtn(){
      let queryData = this.$refs.ProSelectCity.queryData
      let lanId = '';
      if(queryData.proSelect == ''){
        this.$alert('省份:不能为空!','提示',{type:'warning'})
        return
      }
      if(queryData.citySelect == '' &&  queryData.proSelect != "500182716" && queryData.proSelect != "500182954" && queryData.proSelect != "500182957" && queryData.proSelect != "500181505"){
        this.$alert('地市:不能为空!','提示',{type:'warning'})
        return
      }
      if(queryData.citySelect == ''){
        lanId = queryData.proSelect;
      }
      let params = {
        custId: this.$route.query.custId,
        provinceId: this.$refs.ProSelectCity.queryData.proSelect,
        lanId: lanId == '' ? this.$refs.ProSelectCity.queryData.citySelect : this.$refs.ProSelectCity.queryData.proSelect,
        staffId: this.$route.query.staffId,
      };
      const response = await CustRelationManage.custAutoSynch(params);
      if(response.code == 200) {
         if(response.meta.resultCode == 0){
           this.$confirm(response.meta.resultMsg, "提示", {
            confirmButtonText: "确定",
            showCancelButton: false,
            closeOnClickModal:false,
            type: "success",
            center: true,
          })
          .then(() => {
              this.syncVisible = false
          })
          .catch(() => {});
         } else {
          this.$message({
            showClose: true,
            message: response.meta.resultMsg,
            type: 'error'
          });
         }
      }
    },
    digShow() {
      this.outerVisible = true;
      this.queryData1 = {
        proSelect: "", //选择的省
        citySelect: "", //选择的城市
        proId: "", //省客户id
        proAId:"",//省账户id
        provinceCustNumber:''
      }
    },
    closeShow() {
      this.outerVisible = false;
      this.changeVisible = false;
      this.syncVisible = false;
    },
    returnClick() {
      this.$router.push({
        path: "/custbaseinf",
        query: {
          // partyId: "2102",
          // staffId: "100078",
          // type: "customerAdd",
        },
      });
    },
    async addCust() {
      let queryData = this.$refs.ProSelectCity.queryData
      let lanId = '';
      if(queryData.proSelect == ''){
        this.$alert('省份:不能为空!','提示',{type:'warning'})
        return
      }
      if(queryData.citySelect == '' &&  queryData.proSelect != "500182716" && queryData.proSelect != "500182954" && queryData.proSelect != "500182957" && queryData.proSelect != "500181505"){
           this.$alert('地市:不能为空!','提示',{type:'warning'})
           return
        }
        if(queryData.citySelect == ''){
          lanId = queryData.proSelect;
        }
        if(queryData.proId == ''){
          this.$alert('省客户ID:不能为空!','提示',{type:'warning'})
          return
        }
      let params = {
        jtCustNumber: this.$route.query.oldPartyCode,
        custId: this.$route.query.custId,
        provinceId: this.$refs.ProSelectCity.queryData.proSelect,
        lanId: lanId == '' ? this.$refs.ProSelectCity.queryData.citySelect : this.$refs.ProSelectCity.queryData.proSelect,
        provinceCustId: this.$refs.ProSelectCity.queryData.proId,
        provinceCustNumber: this.$refs.ProSelectCity.queryData.provinceCustNumber,
        staffId: this.$route.query.staffId,
        actType: "ADD",
      };
      const response = await CustRelationManage.custRelMaintain(params);
      if (response.code == 200) {
        if(response.meta.resultCode == 0){
          this.outerVisible = false;
          this.getCusRelList();
        }else {
          this.$message({
            showClose: true,
            message: response.meta.resultMsg,
            type: 'error'
          });
        }
      }
    },
    //修改客户信息确定事件
    async jtCustBtn() {
      let params = {
        jtCustNumber: this.changeRowInfo.jtCustNumber,
        // custId: "",//手动修改时不传，查询集团客户是传选中的集团客户custId值
        provinceId: this.changeRowInfo.provinceId,
        lanId: this.changeRowInfo.lanId,
        provinceCustId: this.changeRowInfo.provinceCustId,
        provinceCustNumber: this.changeRowInfo.provinceCustNumber,
        staffId: this.$route.query.staffId,
        actType: "MOD",
        custOrmRelId: this.changeRowInfo.custOrmRelId,
        custIdOld: this.changeRowInfo.custId,
        jtCustNumberOld: this.jtCustNumberOld,
      };
      const response = await CustRelationManage.custRelMaintain(params);
      if (response.code == 200) {
        if (response.meta.resultCode != 0) {
          this.$alert(response.meta.resultMsg, "提示", { type: "warning" });
        } else {
          this.changeVisible = false;
          this.getCusRelList();
        }
      }
    },
    //修改客户关系信息
    handleClick(val) {
      this.changeVisible = true;
      this.jtCustNumberOld = val.jtCustNumber;
      this.changeRowInfo = Object.assign({},val);
    },
    //删除关联客户事件
    delectClick(row) {
      this.$confirm("确认删除该客户关系？", "提示", {
        confirmButtonText: "确定",
        type: "warning",
        cancelButtonText: "取消",
      })
        .then(async () => {
          let params = {
            custOrmRelId: row.custOrmRelId,
            custId: this.$route.query.custId,
            provinceId: row.provinceId,
            lanId: row.lanId,
            provinceCustId: row.provinceCustId,
            actType: "DEL",
            jtCustNumber: row.jtCustNumber,
          };
          const response = await CustRelationManage.custRelMaintain(params);
          if (response.code == 200) {
            this.getCusRelList();
          }
        })
        .catch(() => {});
    },
    //切换页码
    pageHandleCurrentChange(val) {
      this.tablePage.pageIndex = val
      this.getCusRelList();
    },
    //切换每页数量
    pageHandleSizeChange(val){
      this.tablePage.pageSize = val
      this.getCusRelList();
    },
    //选择证件类型触发事件
    ChangeIdCard(val) {
      
    },
    //查询省客户事件
    checkProCust() {
      this.proTablePage.pageIndex = 1;
      this.getProCust()
    },
    async getProCust(){
      let params = {
        custName:this.getProData.custName,
        partyNbr:this.getProData.idCard,
        pageIndex:this.proTablePage.pageIndex,
        pageSize:this.proTablePage.pageSize,
        provinceId:this.proSelectVal.proSelect,
        certType:this.getProData.idType,
        certNum:this.getProData.idCardNum,
        provinceCustId:this.getProData.proId
      }
      const reponse = await CustRelationManage.getCustProList(params)
      if(reponse.code == 200){
         this.proList = reponse.meta.customers;
         this.proTablePage.rowCount = reponse.meta.rowCount
      }
    },
    chooseProCust(val){
      this.queryData1.proId = val.custId
      this.queryData1.provinceCustNumber = val.custNumber
      this.innerVisible = false;
    },
    //查询集团客户
    checkBtn(){
      this.jtTablePage.pageIndex = 1
      if(this.getJtData.idType!="" && this.getJtData.certNum == "" && this.getJtData.idCardNum == ""){
        this.$alert('证件类型需和证件号码或者身份证号码一起查询','提示',{type:'warning'})
        return
      }
      this.checkJtCust();
    },
    //查询集团客户弹窗
    checkCustBtn() {
      this.jtTablePage.pageIndex = 1
      this.changeInnerVisible = true;
      this.checkJtCust()
    },
    //集团客户列表
    async checkJtCust(){
      let parmas = {
         pageIndex:this.jtTablePage.pageIndex,
         pageSize:this.jtTablePage.pageSize,
         custName:this.getJtData.custName,
         custNameLike:'2',
         oldPartyCode:this.getJtData.oldPartyCode,
         oldPartyCodeLike:'2',
         searchFlag:'3',
         empeeId:this.$route.query.staffId,
         certType:this.getJtData.idType,
         certNum:this.getJtData.certNum,
         partyNbr:this.getJtData.idCardNum
      }
      const response = await CustRelationManage.getCustList(parmas);
      if(response.code == 200) {
         this.jtList = response.meta.customers;
         this.jtTablePage.rowCount = response.meta.pageInfo.rowCount;
         this.jtList.forEach(item=>{
           item['custManager'] = this.isNull(item.custManagerNameA) + ' ' + this.isNull(item.custManagerNameB);
           item.createDate = 
            item.createDate.substring(0, 4) +
            "-" +
            item.createDate.substring(4, 6) +
            "-" +
            item.createDate.substring(6, 8) +
            " " +
            item.createDate.substring(8, 10) +
            ":" +
            item.createDate.substring(10, 12) +
            ":" +
            item.createDate.substring(12, 14);
         })
         this.getCusRelList()
      }
    },
    //省列表改变当前页触发事件
    proPageChange(val) {
      this.proTablePage.pageIndex = val
      this.getProCust()
    },
    //集团列表改变当前页触发事件
    jtPageChange(val) {
      this.jtTablePage.pageIndex = val
      this.checkJtCust(val)
    },
    //同步集团客户到省弹窗
    syncCustPro(){
      this.syncVisible = true
    },
    async getCustList(val) {
      let parmas = {
        pageIndex: "1",
        pageSize: this.tablePage.pageSize,
        custNumber: this.$route.query.oldPartyCode,
        provinceId: val.proSelect,
        lanId: val.citySelect,
        provinceCustId: val.proId,
      };
      const response = await CustRelationManage.getCusRelList(parmas);
      if (response.code == 200) {
        this.custArr = response.meta.executeSqlResp;
        this.tablePage = response.meta.pageInfo;
        this.tablePage.pageSize = 5;
        this.custArr.forEach((item) => {
          item.createDate =
            item.createDate.substring(0, 4) +
            "-" +
            item.createDate.substring(4, 6) +
            "-" +
            item.createDate.substring(6, 8) +
            " " +
            item.createDate.substring(8, 10) +
            ":" +
            item.createDate.substring(10, 12) +
            ":" +
            item.createDate.substring(12, 14);
        });
      }
    },
    chooseJtCust(val){
      this.changeRowInfo.jtCustNumber = val.oldPartyCode;
      this.changeInnerVisible = false;
    },
    innerDigShow(val) {
      this.innerVisible = true;
      this.getProData.custName = this.custName;
      this.getProData.idCard = this.$route.query.partyNbr;
      this.proSelectVal = val;
      this.getProCust()
    },
    isNull(val) {
      if (val == "NaN" || val == "null" || val == "undefined" || val == undefined) {
        return (val = "");
      }else {
        return val
      }
    },
  },
};
</script>
<style lang='scss' scoped>
.container {
  height: 100%;
  width: 100%;
  background-color: #fff;
  padding: 0.2rem;
  overflow-x: hidden;
}
.cust-r-title {
  width: 100%;
  padding-bottom: 15px;
  .cust-r-l {
    font-size: 15px;
    color: #467cd4;
  }
  .cust-r-c {
    background: #467cd4;
    font-size: 13px;
    color: #fff;
    cursor: pointer;
  }
  .cust-r-r {
    font-size: 13px;
    background: #467cd4;
    font-size: 13px;
    color: #fff;
    cursor: pointer;
  }
}
.m-pagination {
  margin-top: 20px;
  margin-right: 100px;
  text-align: right;
}
.btnBox {
  width: 100%;
  text-align: center;
}
.confirmBtn {
  width: 80px;
  background: #467cd4;
  color: #fff;
  margin: 50px 10px 50px 20px;
}
.returnBtn {
  width: 80px;
  color: #fff;
  margin: 10px 0;
}
.checkBtn {
  background: #467cd4;
  color: #fff;
}
.jt-ipt {
  padding: 0 0.1rem;
}
</style>
